home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 3 / Cream of the Crop 3.iso / comm / wnos5src.zip / REINDEX.C < prev    next >
Text File  |  1993-08-09  |  2KB  |  102 lines

  1. #include <fcntl.h>
  2. #include <sys\stat.h>
  3. #include <io.h>
  4. #include "global.h"
  5.  
  6.  
  7. #define LEN_BID         12
  8. #define NLEN_BID        12+1
  9.  
  10. #define LEN_SUBJECT     50
  11. #define NLEN_SUBJECT    50
  12.  
  13. #define LEN                40
  14. #define NLEN            40
  15.  
  16.  
  17. #define NORMAL        0
  18. #define DELETED        1
  19. #define PRIVATE        2
  20. #define BULLETIN    4
  21. #define NEWS        8
  22.  
  23. struct old_index {
  24.   int32 size;
  25.   int32 date;
  26.   int32 mesg;
  27.   char lifetime_h;
  28.   char lifetime_l;
  29.   char flag;
  30.   char bid[LEN_BID];
  31.   char subject[LEN_SUBJECT];
  32.   char to[LEN];
  33.   char at[LEN];
  34.   char from[LEN];
  35.   char from_at[LEN];
  36. };
  37.  
  38. struct new_index {
  39.   int32 size;
  40.   int32 date;
  41.   int32 mesg;
  42.   char lifetime_h;
  43.   char lifetime_l;
  44.   char flag;
  45.   char bid[NLEN_BID];
  46.   char subject[NLEN_SUBJECT];
  47.   char to[NLEN];
  48.   char at[NLEN];
  49.   char from[NLEN];
  50.   char from_at[NLEN];
  51. };
  52.  
  53.  
  54. main()
  55. {
  56.     int fdoindex = -1;
  57.     int fdnindex = -1;
  58.     unsigned uoindex_len = sizeof(struct old_index);
  59.     unsigned unindex_len = sizeof(struct new_index);
  60.  
  61.     struct old_index oindex;
  62.     struct new_index nindex;
  63.  
  64.  
  65.     if((fdoindex = open("index",O_RDWR | O_CREAT | O_BINARY,S_IREAD | S_IWRITE)) < 1) {
  66.         exit(1);
  67.     }
  68.     if((fdnindex = open("nindex",O_RDWR | O_CREAT | O_BINARY,S_IREAD | S_IWRITE)) < 1) {
  69.         exit(1);
  70.     }
  71.     lseek(fdoindex,0,SEEK_SET);
  72.  
  73.     while(read(fdoindex,&oindex,uoindex_len) == uoindex_len) {
  74.         if(oindex.flag & DELETED) {
  75.             continue;
  76.         }
  77.         memset(&nindex,0,unindex_len);
  78.  
  79.         nindex.size = oindex.size;
  80.         nindex.date = oindex.date;
  81.         nindex.mesg = oindex.mesg;
  82.         nindex.lifetime_h = oindex.lifetime_h;
  83.         nindex.lifetime_l = oindex.lifetime_l;
  84.         nindex.flag = oindex.flag;
  85.         strncpy(nindex.bid,oindex.bid,min(LEN_BID,NLEN_BID));
  86.         strncpy(nindex.subject,oindex.subject,min(LEN_SUBJECT,NLEN_SUBJECT));
  87.         strncpy(nindex.to,oindex.to,min(LEN,NLEN));
  88.         strncpy(nindex.at,oindex.at,min(LEN,NLEN));
  89.         strncpy(nindex.from,oindex.from,min(LEN,NLEN));
  90.         strncpy(nindex.from_at,oindex.from_at,min(LEN,NLEN));
  91.  
  92.         if(write(fdnindex,&nindex,unindex_len) != unindex_len) {
  93.             close(fdoindex);
  94.             close(fdnindex);
  95.             exit(1);
  96.         }
  97.     }
  98.     close(fdnindex);
  99.     close(fdoindex);
  100.     exit(0);
  101.     return 0;
  102. }